package com.ccys.cms.controller.masterData;

import com.ccys.cms.service.masterData.ClinicService;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.masterData.ClinicDto;
import com.ccys.db.vo.masterData.ClinicPageQueryVo;
import com.ccys.db.vo.masterData.ClinicQueryByGroupIdVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @program: WhiteCoat
 * @description: 诊所接口
 * @author: ZhangJingCan
 * @create: 2023-12-14 13:53
 **/

@RestController
@RequestMapping("masterData")
@Api(tags = "masterData-诊所接口")
public class ClinicController {

    @Autowired
    private ClinicService clinicService;


    @PostMapping("clinic")
    @ApiOperation("保存诊所")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id/修改必传", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "groupId", value = "groupId", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "companyId", value = "companyId", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "countryId", value = "countryId", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "name", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "address", value = "address", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "phone", value = "phone", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "licenseNumber", value = "页面显示为：License no", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "gstRegistered", value = "gstRegistered", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "gstRegistrationNo", value = "gstRegistered为1的时候这个字段必传", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "logoType", value = "0:use company logo ; 1:create", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "image", value = "logoType为1时，这个字段必传", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "appointmentOfflineDocument", value = "页面显示：Documents required for in-clinic appointments", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "referralEmail", value = "页面显示：Referral letter notiﬁcation email address", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "memoEmail", value = "页面显示：Memo notiﬁcation email address", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "appointmentEmail", value = "页面显示：Appointment notiﬁcation email address", required = false, dataType = "string", paramType = "query"),
    })
    public ResponseResult saveClinic(@ApiIgnore ClinicDto dto) {
        return clinicService.saveClinic(dto);
    }


    @PutMapping("clinic")
    @ApiOperation("修改诊所")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id/修改必传", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "groupId", value = "groupId", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "companyId", value = "companyId", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "countryId", value = "countryId", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "name", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "address", value = "address", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "phone", value = "phone", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "licenseNumber", value = "页面显示为：License no", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "gstRegistered", value = "gstRegistered", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "gstRegistrationNo", value = "gstRegistered为1的时候这个字段必传", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "logoType", value = "0:use company logo ; 1:create", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "image", value = "logoType为1时，这个字段必传", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "appointmentOfflineDocument", value = "页面显示：Documents required for in-clinic appointments", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "referralEmail", value = "页面显示：Referral letter notiﬁcation email address", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "memoEmail", value = "页面显示：Memo notiﬁcation email address", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "appointmentEmail", value = "页面显示：Appointment notiﬁcation email address", required = false, dataType = "string", paramType = "query"),
    })
    public ResponseResult edit(@ApiIgnore ClinicDto dto) {
        return clinicService.saveClinic(dto);
    }

    @DeleteMapping("clinic")
    @ApiOperation("根据ID删除诊所")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult deleteClinic(@ApiIgnore ClinicDto dto) {
        return clinicService.deleteClinic(dto);
    }


    @GetMapping("clinic/page")
    @ApiOperation("分页查询诊所")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "name模糊查询", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "groupId", value = "groupId", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "companyId", value = "companyId", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "gstRegistered", value = "0/1/查询所有传null", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "gstRegistrationNo", value = "gstRegistrationNo模糊查询", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "0/1,查询所有传null", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startDate", value = "开始日期,格式:yyyy-MM-dd", required = false, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期,格式:yyyy-MM-dd", required = false, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "orderByStr",
                    value = "(默认传：t1.created_on descend),(左到右依次:t1.name,t3.group_name,t4.company_name,t1.license_number,t1.phone,t1.address,t1.status,t2.user_fullname,t1.created_on)",
                    required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult<PageInfo<ClinicPageQueryVo>, Object> findPageClinic(@ApiIgnore ClinicDto dto) {
        return clinicService.findPageClinic(dto);
    }


    @PutMapping("clinic/status")
    @ApiOperation("根据ID修改诊所状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态：0-禁用，1-启用", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateClinicStatus(@ApiIgnore ClinicDto dto) {
        return clinicService.updateClinicStatus(dto);
    }


    @GetMapping("clinic")
    @ApiOperation("查询集合数据(只会返回id和name用于下拉选择)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "groupId", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "companyId", value = "公司ID", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "doctorId", value = "医生Id", required = false, dataType = "string", paramType = "query"),
    })
    public ResponseResult<List<ClinicQueryByGroupIdVo>, Object> findListClinicByGroupId(@ApiIgnore ClinicDto dto) {
        return clinicService.findListClinicByGroupId(dto);
    }

}
